//
//  LBHTTPConfiguration.m
//  LBNetworking
//
//  Created by WuShiHai on 19/5/30.
//  Copyright (c) 2019 Lebbay. All rights reserved.
//

#import "LBHTTPConfiguration.h"

@implementation LBHTTPConfiguration

- (instancetype)init{
    if ([super init]) {
        _timeoutInterval = 60;
    }
    return self;
}

+ (instancetype)defaultConfiguration{
    LBHTTPConfiguration *configuration = [LBHTTPConfiguration new];
    configuration.timeoutInterval = 60;
    configuration.response = [LBHTTPResponseConfiguration defaultConfiguration];
    return configuration;
}

@end


@implementation LBHTTPResponseConfiguration

+ (instancetype)defaultConfiguration{
    LBHTTPResponseConfiguration *configuration = [LBHTTPResponseConfiguration new];
    configuration.dataKey = @"data";
    configuration.codeKey = @"code";
    configuration.messageKey = @"message";
    return configuration;
}

- (BOOL)isSuccess:(id)code{
    if ([self.successCodeStr isKindOfClass:[NSString class]]) {
        return [code isKindOfClass:[NSString class]] && [code isEqualToString:self.successCodeStr];
    }
    
    if ([code isKindOfClass:[NSString class]] || [code isKindOfClass:[NSNumber class]]) {
        return [code integerValue] == self.successCode;
    }
    
    return NO;
}

@end
